//
//  MHMySettingsViewController.m
//  ManHua
//
//  Created by 江子安 on 15/10/29.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHMySettingsViewController.h"
#import "MHSettingListController.h"
#import "MHSettingDetailViewController.h"
#import <MessageUI/MessageUI.h>

@interface MHMySettingsViewController ()<MFMailComposeViewControllerDelegate>
@property (nonatomic, strong) MHSettingListController *settingListVC;


@end

@implementation MHMySettingsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"设置";
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:kThemeColor,UITextAttributeTextColor,nil];
    
    self.settingListVC = [[UIStoryboard storyboardWithName:@"MHSettingListView" bundle:nil] instantiateInitialViewController];
    __weak MHMySettingsViewController *test = self;
    _settingListVC.goSettingsDetailVCBlock = ^(MHSettingDetailViewController *detailVC){
        [test.navigationController pushViewController:detailVC animated:YES];
    };
    _settingListVC.sendEMailBlock = ^(){
        [test sendEMail];
    };
    self.settingListVC.view.frame = CGRectMake(0, 64, Width, Height - 64);
    [self.view addSubview:self.settingListVC.view];
}

- (void)sendEMail
{
    if (![MFMailComposeViewController canSendMail]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请登录系统邮箱" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {}];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
    }else
    {
        MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc]init];
        mailVC.mailComposeDelegate = self;
        [mailVC setSubject:@"版权申诉"];
        [mailVC setToRecipients:[NSArray arrayWithObject:@"appstorehelp@163.com"]];
        [mailVC setMessageBody:@"App所有收录的内容均来自于互联网的自动索引并收录。任何单位或个人认为通过搜索链接到的第三方漫画、小說内容可能涉嫌侵犯其信息网络传播权，应该及时向我们提出书面权利通知，并提供身份证明、权属证明及详细侵权情况证明。我们在收到上述法律文件后，将会依法尽快断开相关链接内容。\n\n发自我的 iPhone" isHTML:NO];
        [self presentViewController:mailVC animated:YES completion:nil];
    }
    
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [controller dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
